﻿using Pumpkin.FrameBase;
using Pumpkin.Utils;

namespace UIUtils
{
    public class UIHandler
    {
        private static UIHandler Ins = null;
        private CrossDomainInstance crossHandler;

        public static UIHandler GetInstance()
        {
            if (Ins == null)
            {
                Ins = new UIHandler();
            }

            return Ins;
        }

        public UIHandler()
        {
            if (Ins != null)
                Log.LogError("UIHandler must be a singleton");
            Ins = this;
            crossHandler = CrossInstanceFactory.Instance.CreateWithInstantial(BaseCrossType.HotFixUIHandler);
        }

        //经测试ILRuntime热更内部无法使用Delegate.CreateDelegate()方法，
        //而且每次直接在listener上绑定热更里面委托，需额外创建配备器
        //这里将采取直接把listener中的委托在unity主程内赋值，并在热更内部维护调用列表的方法。
        //public void BindEventHandlers(string handleCls, string handler, UIBehaviour.UIActionType type, UIEventListener listener)
        //{
        //    this.StaticInvoke("DoBindEventHandlers", handleCls, handler, type, listener);
        //}

        public object GetHotFixCls(string handleCls)
        {
            return crossHandler.StaticInvoke("DoGetHotFixCls", handleCls);
        }
    }
}